package org.fat.nerd.actd.sharding.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.fat.nerd.actd.sharding.beans.entity.Order;
import org.fat.nerd.actd.sharding.config.DataSourceContextHolder;
import org.fat.nerd.actd.sharding.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author TanXin
 * @since 2022-02-25
 */
@Api(tags = "订单")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @ApiOperation("添加")
    @PostMapping("/addUser")
    private Object addUser(@RequestBody Order order) {
        order.setCreateTime(LocalDate.now());
        boolean save = orderService.save(order);
        return order;
    }

    @ApiOperation("添加2")
    @PostMapping("/addUser2")
    private Object addUser2(@RequestBody Order order) {
        DataSourceContextHolder.setDBType("test_01");
        order.setCreateTime(LocalDate.now());
        boolean save = orderService.save(order);
        int i = 10/0;
        return order;
    }

    @ApiOperation("列表")
    @PostMapping("/list")
    private List<Order> list() {
        return orderService.list();
    }
}

